﻿using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using TCS.Model;
namespace TCS.BLL
{
    /// <summary>
	/// 帮商会员信息表
	/// </summary>
	public partial class MemberInfo
	{
		private readonly TCS.DAL.MemberInfo dal=new TCS.DAL.MemberInfo();
		public MemberInfo()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists()
		{
			return dal.Exists();
		}
         /// <summary>
        /// 是否存在该记录
         /// </summary>
         /// <param name="memberId">用户ID</param>
         /// <returns></returns>
        public bool Exists(int memberId)
        {
            return dal.Exists(memberId);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public bool Exists(string name,string pwd)
        {
            return dal.Exists(name,pwd);
        }
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(TCS.Model.MemberInfo model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(TCS.Model.MemberInfo model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			
			return dal.Delete(Id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return dal.DeleteList(Idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public TCS.Model.MemberInfo GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}
        /// <summary>
        /// 根据用户名得到一个实体
        /// </summary>
        /// <param name="name">用户名</param>
        /// <returns></returns>
        public TCS.Model.MemberInfo GetModel(string  name)
        {

            return dal.GetModel(name);
        }

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public TCS.Model.MemberInfo GetModelByCache(int Id)
		{
			
			string CacheKey = "MemberInfoModel-" + Id;
			object objModel = LTP.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
						LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (TCS.Model.MemberInfo)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<TCS.Model.MemberInfo> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<TCS.Model.MemberInfo> DataTableToList(DataTable dt)
		{
			List<TCS.Model.MemberInfo> modelList = new List<TCS.Model.MemberInfo>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				TCS.Model.MemberInfo model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new TCS.Model.MemberInfo();
					if(dt.Rows[n]["Id"].ToString()!="")
					{
						model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
					}
					model.MI_username=dt.Rows[n]["MI_username"].ToString();
					model.MI_password=dt.Rows[n]["MI_password"].ToString();
					model.MI_Email=dt.Rows[n]["MI_Email"].ToString();
					model.MI_TrueName=dt.Rows[n]["MI_TrueName"].ToString();
					if(dt.Rows[n]["MemberType"].ToString()!="")
					{
						model.MemberType=int.Parse(dt.Rows[n]["MemberType"].ToString());
					}
					model.MI_phone=dt.Rows[n]["MI_phone"].ToString();
					model.Company=dt.Rows[n]["Company"].ToString();
					if(dt.Rows[n]["VIPPrice"].ToString()!="")
					{
						model.VIPPrice=decimal.Parse(dt.Rows[n]["VIPPrice"].ToString());
					}
					if(dt.Rows[n]["AddDate"].ToString()!="")
					{
						model.AddDate=DateTime.Parse(dt.Rows[n]["AddDate"].ToString());
					}
					if(dt.Rows[n]["startDate"].ToString()!="")
					{
						model.startDate=DateTime.Parse(dt.Rows[n]["startDate"].ToString());
					}
					if(dt.Rows[n]["endDate"].ToString()!="")
					{
						model.endDate=DateTime.Parse(dt.Rows[n]["endDate"].ToString());
					}
					if(dt.Rows[n]["isEnable"].ToString()!="")
					{
						if((dt.Rows[n]["isEnable"].ToString()=="1")||(dt.Rows[n]["isEnable"].ToString().ToLower()=="true"))
						{
						model.isEnable=true;
						}
						else
						{
							model.isEnable=false;
						}
					}
					if(dt.Rows[n]["verify"].ToString()!="")
					{
						model.verify=int.Parse(dt.Rows[n]["verify"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
        public void UpdatePassword(int id, string pwd) 
        {
            dal.UpdatePassword(id,pwd);
        }
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

